package com.ruoyi.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * 文件说明
 * 描述：
 * 作者：Xing Gang
 * 日期：2020-12-21
 * 网址：https://weiku.co
 * 邮箱：xinggang.china@gmail.com
 */
@Configuration
public class DataSourceConfig {

    @Autowired
    private ApplicationContext applicationContext;

    @Bean(name = "ds1")
    public DataSource dataSource(Environment environment) {
        //配置数据源连接器，此处使用hikari，也可以换为Druid
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl(environment.getProperty("spring.datasource.druid.master.url"));
        ds.setUsername(environment.getProperty("spring.datasource.druid.master.username"));
        ds.setPassword(environment.getProperty("spring.datasource.druid.master.password"));
        ds.setDriverClassName(environment.getProperty("spring.datasource.driver-class-name"));
        return ds;
    }
}
